package com.heima.springai.controller;

import com.heima.springai.service.VoiceService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api")
public class VoiceController {

    @PostMapping("/asr")
    public String asr(@RequestParam("audio") MultipartFile file) throws Exception {
        return VoiceService.asr(file);          // 返回识别文本
    }

    @PostMapping("/chat")
    public String chat(@RequestBody Question q) {
        // TODO: 换成你的 LLM 接口；这里先 mock
        return "你刚才说的是：" + q.getQuestion() + "，但我还没接 LLM。";
    }

    @PostMapping("/tts")
    public byte[] tts(@RequestBody TtsRequest r) {
        return VoiceService.tts(r.getText());   // 返回 wav 二进制
    }

    /* 接收 JSON 用的小 DTO */
    static class Question { private String question; public String getQuestion(){return question;} }
    static class TtsRequest { private String text; public String getText(){return text;} }
}
